var https = "https://www.moreclub.cn/";
var WxParse = require('../../wxParse/wxParse.js');
var app = getApp();
var activityId;

// var util = require('../../utils/util.js')
var add0 = function (m) {
  return m < 10 ? '0' + m : m
}
var time = function (shijianchuo) {
  var time = new Date(shijianchuo);
  // var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  // var h = time.getHours();
  // var mm = time.getMinutes();
  // var s = time.getSeconds();
  // return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
  return add0(m) + '-' + add0(d)
}

var time3 = function (shijianchuo) {
  var time = new Date(shijianchuo);
  // var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var week;
  var day = time.getDay();
  // var s = time.getSeconds();
  switch (day) {
    case 0: week = "周天"; break
    case 1: week = "周一"; break
    case 2: week = "周二"; break
    case 3: week = "周三"; break
    case 4: week = "周四"; break
    case 5: week = "周五"; break
    case 6: week = "周六"; break
  }
  // return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
  // return add0(h) + ':' + add0(mm)
  //return day; 
  return add0(m) + '月' + add0(d) + '日' + ' ' + week
}

var time2 = function (shijianchuo) {
  var time = new Date(shijianchuo);
  var h = time.getHours();
  var mm = time.getMinutes();
  return add0(h) + ':' + add0(mm)
}

Page({
  onLoad: function (options) {
    // 生命周期函数--监听页面加载
   activityId = options.activityId;
    var that = this;
    // var activityId = e.target.dataset.activityId
    // that.setData({
    //   activityId: activityId
    // });


    wx.request({//活动
      //url: https + 'v1/activity/open/intros?activityId=' + options.clickLink,
      url: https + 'v1/activity/open/intros?activityId=' + activityId,
      dataType: "json",
      success: function (res) {
        console.log(res)
        if (res.data.success) {
          console.log(res.data.data)
          var activeData = res.data.data;

          //酒类
          var drinks = activeData.featuredDrink;
          var htp = 'http://more-image.oss-cn-beijing.aliyuncs.com/activitydetailtag/drink_';
          var cn = drinks.indexOf(',');
          var curlist = [];

          if (cn > 0) {
            for (var r = 0; r < drinks.length; r++) {
              if (drinks[r] == ',') {
                var arrdrink = drinks.split(',')

              }
            }
          } else {
            if (drinks == '2') {
              var chDrink = '葡萄酒'
              var src = htp + '2' + '.png'
            }
            if (drinks == '3') {
              var chDrink = '白兰地'
              var src = htp + '3' + '.png'
            }
            if (drinks == '4') {
              var chDrink = '威士忌'
              var src = htp + '4' + '.png'
            }
            if (drinks == '5') {
              var chDrink = '鸡尾酒'
              var src = htp + '5' + '.png'
            }
            if (drinks == '6') {
              var chDrink = '精酿啤酒'
              var src = htp + '6' + '.png'
            }
            if (drinks == '15') {
              var chDrink = '清酒'
              var src = htp + '15' + '.png'
            }
            if (drinks == '17') {
              var chDrink = '香槟'
              var src = htp + '17' + '.png'
            }
            if (drinks == '18') {
              var chDrink = '白兰地'
              var src = htp + '18' + '.png'
            }
            if (drinks == '16') {
              var chDrink = '进口啤酒'
              var src = htp + '16' + '.png'
            }
            if (drinks == '7') {
              var chDrink = '葡萄酒'
              var src = htp + '7' + '.png'
            }
            var obj = {};//创建新对象
            obj.chDrink = chDrink;
            obj.src = src;
            curlist.push(obj);

          }
          if (cn > 0) {
            for (var j = 0; j < arrdrink.length; j++) {
              console.log(arrdrink[j])
              if (arrdrink[j] == '1') {
                var chDrink = '进口啤酒'
                var src = htp + '1' + '.png'

              }

              if (arrdrink[j] == '2') {
                var chDrink = '葡萄酒'
                var src = htp + '2' + '.png'
              }
              if (arrdrink[j] == '3') {
                var chDrink = '白兰地'
                var src = htp + '3' + '.png'
              }
              if (arrdrink[j] == '4') {
                var chDrink = '威士忌'
                var src = htp + '4' + '.png'
              }
              if (arrdrink[j] == '5') {
                var chDrink = '鸡尾酒'
                var src = htp + '5' + '.png'
              }
              if (arrdrink[j] == '6') {
                var chDrink = '精酿啤酒'
                var src = htp + '6' + '.png'
              }
              if (arrdrink[j] == '15') {
                var chDrink = '清酒'
                var src = htp + '15' + '.png'
              }
              if (arrdrink[j] == '17') {
                var chDrink = '香槟'
                var src = htp + '17' + '.png'
              }
              if (arrdrink[j] == '18') {
                var chDrink = '白兰地'
                var src = htp + '18' + '.png'
              }
              if (arrdrink[j] == '16') {
                var chDrink = '进口啤酒'
                var src = htp + '16' + '.png'
              }
              if (arrdrink[j] == '7') {
                var chDrink = '葡萄酒'
                var src = htp + '7' + '.png'
              }
              var obj = {};//创建新对象
              obj.chDrink = chDrink;
              obj.src = src;
              curlist.push(obj);
            }
          }


          console.log(curlist)

          var shijianchuo1 = activeData.startTime;
          var shijianchuo2 = activeData.endTime;
          time3(shijianchuo1)
          var dataTime0 = time3(shijianchuo1)
          time2(shijianchuo1)
          var dataTime1 = time2(shijianchuo1)
          time2(shijianchuo2)
          var dataTime2 = time2(shijianchuo2)
          console.log(dataTime1)

          var taglist = activeData.tag;
          var cont = taglist.indexOf(',');
          if (cont > 0) {
            for (var i = 0; i < taglist.length; i++) {
              if (taglist[i] == ',') {
                var tags = taglist.split(",");
              }

            }
          } else {
            var tags = taglist
          }

          var article1 = activeData.details;
          that.setData({
            activeData: activeData,
            taglist: taglist,
            tags: tags,
            cont: cont,
            dataTime2: dataTime2,
            dataTime1: dataTime1,
            dataTime0: dataTime0,
            curlist: curlist,

          })
          WxParse.wxParse('article1', 'html', article1, that, 5);
        }

      }

    })


  },
  onShareAppMessage: function () {
    // 用户点击右上角分享
    return {
      title: encodeURI(options.title), // 分享标题
      desc: encodeURI(options.title), // 分享描述
      path: '/pages/information/information?id=' + options.id + '&type=' + options.type + '&activityId=' + options.clickLink
    }

  },

  openMap: function (event) {
    wx.openLocation({
      latitude: event.target.dataset.lat, // 纬度，范围为-90~90，负数表示南纬
      longitude: event.target.dataset.lng, // 经度，范围为-180~180，负数表示西经
      scale: 28, // 缩放比例          
    })
  }


})